package com.xlongwei.accounts.view;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import org.noear.snack.annotation.ONodeAttr;

import lombok.Data;

@Data
public class Yearly {
    private @ONodeAttr(serialize = false) AtomicLong incomes = new AtomicLong(), outcomes = new AtomicLong();
    private @ONodeAttr(serialize = false) Map<String, Monthly> months = new LinkedHashMap<>();
    @ONodeAttr(serialize = false)
    private Map<String, AtomicLong> name_incomes = new LinkedHashMap<>(), name_outcomes = new LinkedHashMap<>();

    private String year, sum_in, sum_out, net_assets;
    private Map<String, String> sum_ins = new LinkedHashMap<>(), sum_outs = new LinkedHashMap<>();
    private List<Monthly> records;

    @Data
    public static class Monthly {
        @ONodeAttr(serialize = false)
        private AtomicLong incomes = new AtomicLong(), outcomes = new AtomicLong();
        @ONodeAttr(serialize = false)
        private Map<Integer, AtomicLong> id_incomes = new LinkedHashMap<>(), id_outcomes = new LinkedHashMap<>();

        private String month, sum_in, sum_out, net_assets;
        private Map<String, String> sum_ins = new LinkedHashMap<>(), sum_outs = new LinkedHashMap<>();

        public AtomicLong id_incomes(Integer id) {
            return id_incomes.computeIfAbsent(id, (key) -> new AtomicLong());
        }

        public AtomicLong id_outcomes(Integer id) {
            return id_outcomes.computeIfAbsent(id, (key) -> new AtomicLong());
        }
    }

    public AtomicLong name_incomes(String name) {
        return name_incomes.computeIfAbsent(name, (key) -> new AtomicLong());
    }

    public AtomicLong name_outcomes(String name) {
        return name_outcomes.computeIfAbsent(name, (key) -> new AtomicLong());
    }
}
